<template>
  <div ref="chart" style="width: 100%; height: 400px;"></div>
</template>
<script>
import * as echarts from 'echarts';

export default {
  data() {
    return {
      // 模拟数据：积分来源及其对应的数量
      chartData: [
        { name: '建议提交', value: 200 },
        { name: '活动奖励', value: 150 },
        { name: '兑换消耗', value: 100 },
      ],
    };
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      const chart = echarts.init(this.$refs.chart);

      // 构造饼图数据
      const option = {
        title: {
          text: '积分获取渠道分布',
          subtext: '按来源分类',
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            name: '积分来源',
            type: 'pie',
            radius: '50%',
            data: this.chartData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)',
              },
            },
          },
        ],
      };

      // 设置图表选项
      chart.setOption(option);
    },
  },
};
</script>
